package com.ruoyi.web.controller.train;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.TrainingBaseUser;
import com.ruoyi.system.service.ITrainingBaseUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 临床培训基地对应管理员Controller
 *
 * @author dp
 * @date 2023-11-30
 */
@Api(tags = {"临床培训基地对应管理员"})
@RestController
@RequestMapping("/training/user")
public class TrainingBaseUserController extends BaseController {
    @Autowired
    private ITrainingBaseUserService trainingBaseUserService;

    /**
     * 查询临床培训基地对应管理员列表
     */
    @ApiOperation(value = "临床培训基地对应管理员列表", notes = "查询临床培训基地对应管理员列表详情", tags = {"临床培训基地对应管理员管理"})
    //@PreAuthorize("@ss.hasPermi('system:USER:list')")
    @GetMapping("/list")
    public TableDataInfo list(TrainingBaseUser trainingBaseUser) {
        startPage();
        List<TrainingBaseUser> list = trainingBaseUserService.selectTrainingBaseUserList(trainingBaseUser);
        return getDataTable(list);
    }

    /**
     * 导出临床培训基地对应管理员列表
     */
    @ApiOperation(value = "临床培训基地对应管理员列表导出", notes = "导出临床培训基地对应管理员列表详情", tags = {"临床培训基地对应管理员管理"})
    //@PreAuthorize("@ss.hasPermi('system:USER:export')")
    @Log(title = "临床培训基地对应管理员", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TrainingBaseUser trainingBaseUser) {
        List<TrainingBaseUser> list = trainingBaseUserService.selectTrainingBaseUserList(trainingBaseUser);
        ExcelUtil<TrainingBaseUser> util = new ExcelUtil<TrainingBaseUser>(TrainingBaseUser.class);
        util.exportExcel(response, list, "临床培训基地对应管理员数据");
    }

    /**
     * 获取临床培训基地对应管理员详细信息
     */
    @ApiOperation(value = "获取临床培训基地对应管理员详细信息", notes = "获取临床培训基地对应管理员详细信息详情", tags = {"临床培训基地对应管理员管理"})
    //@PreAuthorize("@ss.hasPermi('system:USER:query')")
    @GetMapping(value = "/{baseUserId}")
    public AjaxResult getInfo(@PathVariable("baseUserId") Long baseUserId) {
        return success(trainingBaseUserService.selectTrainingBaseUserByBaseUserId(baseUserId));
    }

    /**
     * 新增临床培训基地对应管理员
     */
    @ApiOperation(value = "新增临床培训基地对应管理员", notes = "新增临床培训基地对应管理员详情", tags = {"临床培训基地对应管理员管理"})
    //@PreAuthorize("@ss.hasPermi('system:USER:add')")
    @Log(title = "临床培训基地对应管理员", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TrainingBaseUser trainingBaseUser) {
        return toAjax(trainingBaseUserService.insertTrainingBaseUser(trainingBaseUser));
    }

    /**
     * 修改临床培训基地对应管理员
     */
    @ApiOperation(value = "修改临床培训基地对应管理员", notes = "修改临床培训基地对应管理员详情", tags = {"临床培训基地对应管理员管理"})
    //@PreAuthorize("@ss.hasPermi('system:USER:edit')")
    @Log(title = "临床培训基地对应管理员", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TrainingBaseUser trainingBaseUser) {
        return toAjax(trainingBaseUserService.updateTrainingBaseUser(trainingBaseUser));
    }

    /**
     * 删除临床培训基地对应管理员
     */
    @ApiOperation(value = "删除临床培训基地对应管理员", notes = "删除临床培训基地对应管理员详情", tags = {"临床培训基地对应管理员管理"})
    //@PreAuthorize("@ss.hasPermi('system:USER:remove')")
    @Log(title = "临床培训基地对应管理员", businessType = BusinessType.DELETE)
    @DeleteMapping("/{baseUserIds}")
    public AjaxResult remove(@PathVariable Long[] baseUserIds) {
        return toAjax(trainingBaseUserService.deleteTrainingBaseUserByBaseUserIds(baseUserIds));
    }


    /**
     * 批量新增临床培训基地对应管理员
     */
    @ApiOperation(value = "批量新增临床培训基地对应管理员", notes = "批量新增临床培训基地对应管理员详情", tags = {"临床培训基地对应管理员管理"})
    //@PreAuthorize("@ss.hasPermi('system:role:edit')")
    @Log(title = "批量新增临床培训基地对应管理员", businessType = BusinessType.GRANT)
    @PutMapping("/authUser")
    public AjaxResult selectAuthUserAll(Long baseId, Long[] userIds)
    {
        return toAjax(trainingBaseUserService.insertAuthUsers(baseId, userIds));
    }


}
